#include <sysbios/nano/Kernel.h>
#include <sysbios/nano/msp430/CpuIntr.h>
#include <sysbios/nano/msp430/TimerB.h>
#include <xdc/runtime/System.h>

volatile Int IN = 1;

Int count = 3;

typedef struct {
    Kernel_Fiber fiber;
    Kernel_Event expired;
} State;

State gbl;

Void reactor( Ptr me, Kernel_Signal sig )
{
    System_printf("reactor %d\n", count--);

    if (count > 0) {
        TimerB_start(1000, &gbl.expired);
    }
    else {
        System_exit(0);
    }
}

Int main()
{
    volatile Bool idleFlag;

    System_printf("test2\n");

    Kernel_initFiber(&gbl.fiber, 0);
    Kernel_initEvent(&gbl.expired, offsetof (State, expired));

    Kernel_setReactor(&gbl.fiber, reactor);
    Kernel_setSignal(&gbl.expired, 0);

    CpuIntr_enableAll();
    Kernel_start();
    
    TimerB_start(1000, &gbl.expired);

    for (idleFlag = TRUE; idleFlag; ) ;

    return 0;
}
